package mo.leetcode_top;

import java.util.Stack;

public class L155_MinStack {

    private Stack<Integer> stack = new Stack<>();
    private Stack<Integer> min = new Stack<>();

    public L155_MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        //处理最小
        if (min.isEmpty() || min.peek() >= val) {
            min.push(val);
        }
    }

    public void pop() {
        int x = stack.pop();
        //处理最小
        if (!min.isEmpty() && x == min.peek()) {
            min.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }

}
